package com.framework.seedkit.utils.date;

import android.annotation.SuppressLint;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 描述: 这是一个根据具体的时间值(如毫秒数)获取具体的年月日值的时间工具类
 *
 */
@SuppressLint("SimpleDateFormat") public class TimeUtils {

	public static long getCurrentTime() {
		return System.currentTimeMillis();
	}
	
	public static int getYearByMillis(long millis) {
		if (millis <= 0) {
			millis = getCurrentTime();
		}
		
		Date date = new Date(millis);
		Calendar cal = Calendar.getInstance();  
		cal.setTime(date);
		return cal.get(Calendar.YEAR);
	}
	
	public static int getMonthByMillis(long millis) {
		if (millis <= 0) {
			millis = getCurrentTime();
		}
		
		Date date = new Date(millis);
		Calendar cal = Calendar.getInstance();  
		cal.setTime(date);
		return cal.get(Calendar.MONTH) + 1;
	}
	
	public static int getDayByMillis(long millis) {
		if (millis <= 0) {
			millis = getCurrentTime();
		}
		
		Date date = new Date(millis);
		Calendar cal = Calendar.getInstance();  
		cal.setTime(date);
		return cal.get(Calendar.DATE);
	}
	
	public static int getHourByMillis(long millis) {
		if (millis <= 0) {
			millis = getCurrentTime();
		}
		
		Date date = new Date(millis);
		Calendar cal = Calendar.getInstance();  
		cal.setTime(date);
		return cal.get(Calendar.HOUR);
	}
	
	public static int getMiniteByMillis(long millis) {
		if (millis <= 0) {
			millis = getCurrentTime();
		}
		
		Date date = new Date(millis);
		Calendar cal = Calendar.getInstance();  
		cal.setTime(date);
		return cal.get(Calendar.MINUTE);
	}
	
	public static int getSecondeByMillis(long millis) {
		if (millis <= 0) {
			millis = getCurrentTime();
		}
		
		Date date = new Date(millis);
		Calendar cal = Calendar.getInstance();  
		cal.setTime(date);
		return cal.get(Calendar.SECOND);
	}
	
	/**
	 * 获取当前系统时间
	 */
	public static String getCurrentTimeFromat() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date curDate = new Date(System.currentTimeMillis());
		String str = formatter.format(curDate);

		return str;
	}
	
}
